;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Fn binding;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(global-set-key [f1] 'emms-add-playlist)
;;(global-set-key [C-f1] 'info)
(global-set-key [f2] 'emms)
(global-set-key [f3] 'start-jde)
(global-set-key [f4] 'menu-bar-mode)
;;(global-set-key [f5] 'start-abbrev)
;;(global-set-key [f6] 'LaTeX-mode)
(define-key c-mode-base-map [(f7)] 'compile)
(global-set-key [f5] 'eshell)
(global-set-key [f6] 'smart-compile)
(global-set-key [f7] 'LaTeX-math-mode)
;;(global-set-key [f9] 'start-ecb)
;;(global-set-key [f10] 'info)
(global-set-key [f11] 'calendar)
(global-set-key [f12] 'list-bookmarks)
(global-set-key [home] 'beginning-of-buffer)
(global-set-key [end] 'end-of-buffer)
;;(global-set-key [backspace] 'c-hungry-delete-backwards)
(global-set-key (kbd "M-3") 'tabbar-backward-group)
(global-set-key (kbd "M-4") 'tabbar-forward-group)
(global-set-key (kbd "M-1") 'tabbar-backward)
(global-set-key (kbd "M-2") 'tabbar-forward)
(global-set-key   [C-S-return]      'my-dup-line-down)
(global-set-key   [C-M-S-up]        'windmove-up)
(global-set-key   [C-M-S-down]        'windmove-down)
(global-set-key   [C-M-S-left]        'windmove-left)
(global-set-key   [C-M-S-right]        'windmove-right)
(global-set-key   [C-return]      'my-move-line-down)
(global-set-key   [M-S-return]      'my-move-line-up)
(global-set-key   [S-return]        'ue-select-line-down-continued)
(global-set-key (kbd "C--") 'undo)
(global-set-key (kbd "C-=") 'redo)

(global-set-key (kbd "C-c t") 'rotate-text)
(global-set-key (kbd "C-c q") 'my-retate-windows)
(global-set-key (kbd "C-c a") 'his-transpose-windows)
(global-set-key (kbd "C-c u") 'revert-buffer)
(global-set-key (kbd "C-c w") 'ywb-favorite-window-config)
(global-set-key (kbd "C-c g") 'comment-or-uncomment-region)
;;(global-set-key (kbd "f5") 'hs-toggle-hiding)
(global-set-key (kbd "C-c i") 'his-imenu)
(global-set-key (kbd "C-c vm") 'view-mode)
(global-set-key (kbd "C-'") 'comment-dwim)
(global-set-key (kbd "S-SPC") 'set-mark-command)
(global-set-key "%" 'his-match-paren)
(global-set-key (kbd "C-M-=") 'ywb-indent-accoding-to-paren)



;;(global-set-key [(control tab)] 'senator-completion-menu-popup)
(global-set-key [(control c)(k)] 'browse-kill-ring)
;;(global-set-key [(control tab)] 'my-indent-or-complete)
(global-set-key (kbd "C-(") 'swbuff-switch-to-previous-buffer)
(global-set-key (kbd "C-)") 'swbuff-switch-to-next-buffer)
(global-set-key [(control x)(control y)] 'recentf-open-files-compl)
(global-set-key [(control ?\.)] 'ska-point-to-register)
(global-set-key [(control ?\,)] 'ska-jump-to-register)
(global-set-key (kbd "M-g") 'goto-line)

(define-key c-mode-base-map [(control \`)] 'hs-toggle-hiding)
(define-key c-mode-base-map [(return)] 'newline-and-indent)
(define-key c-mode-base-map [(meta \`)] 'c-indent-command)
(define-key c-mode-base-map [(tab)] 'indent-or-complete)
(define-key c-mode-base-map [(meta \[)] 'skeleton-c-mode-left-brace)
;; (define-key c-mode-base-map [(meta ?/)] 'semantic-ia-complete-symbol-menu)
;; (define-key c-mode-base-map [(meta p)] 'semantic-complete-self-insert)

(define-key ctl-x-map "r\C-@" 'rm-set-mark) 
(define-key ctl-x-map [?r ?\C-\ ] 'rm-set-mark) 
(define-key ctl-x-map "r\C-x" 'rm-exchange-point-and-mark) 
(define-key ctl-x-map "r\C-w" 'rm-kill-region) 
(define-key ctl-x-map "r\M-w" 'rm-kill-ring-save) 
(define-key global-map [S-down-mouse-1] 'rm-mouse-drag-region) 


;;(define-key emacs-lisp-mode-map " " 'elisp-space)
(define-key php-mode-map "\C-c\C-d" 'php-debug)
(define-key php-mode-map "\C-c\C-r" 'php-run)
(global-set-key "\C-xrj" 'regadhoc-jump-to-registers)
(global-set-key "\C-x/" 'regadhoc-register)
(global-set-key "\M-?" 'etags-select-find-tag-at-point)
(global-set-key [(control o)] 'other-window) 
(global-set-key (kbd "C-c w")         (quote copy-word))
(global-set-key (kbd "C-c l")         (quote copy-line))
(global-set-key (kbd "C-c p")         (quote copy-paragraph))

;; (global-set-key (kbd "C-c [") 'muse-insert-slide)
;; (global-set-key (kbd "C-c ]") 'muse-insert-src)

(global-set-key (kbd "C-z b c") 'emacs-lisp-byte-compile)
(global-set-key (kbd "C-z b n") 'babel-region)
(global-set-key (kbd "C-z b r") 'babel-region-default)
(global-set-key (kbd "C-z b b") 'babel-buffer-default)
(global-set-key (kbd "C-z b f") 'babel-buffer)
(global-set-key (kbd "C-z c a") 'cfw:open-calendar-buffer)
(global-set-key (kbd "C-z c o") 'cfw:open-org-calendar)
(global-set-key (kbd "C-z c i") '(lambda() (interactive) (cfw:open-ical-calendar "https://www.google.com/calendar/ical/schulei.chu%40gmail.com/private-7a5becb2e9635dc6a39b256a2a3b9120/basic.ics")))
(global-set-key (kbd "C-z c m") 'company-mode)
(global-set-key (kbd "C-z d d") 'delete-cur-word)
(global-set-key (kbd "C-z d s") 'diary-show-all-entries)
(global-set-key (kbd "C-z c c") 'company-complete)
(global-set-key (kbd "C-z l l") 'sdcv-search-pointer)
(global-set-key (kbd "C-z l s") 'sdcv-search-input)
(global-set-key (kbd "C-c d") 'sdcv-search-pointer+)
(global-set-key (kbd "C-z d b") 'ediff-buffers)
(global-set-key (kbd "C-z d p") 'geben)
(global-set-key (kbd "C-z d e") 'geben-end)
(global-set-key (kbd "C-z d f") 'ediff-files)
(global-set-key (kbd "C-z d m") 'doc-mode-fix-tag-doc)
(global-set-key (kbd "C-z d t") 'doc-mode-add-tag-doc)
(global-set-key (kbd "C-z e a") 'edebug-all-defs)
(global-set-key (kbd "C-z e e") 'edebug-defun)
(global-set-key (kbd "C-z f m") 'flyspell-mode)
(global-set-key (kbd "C-z f f") 'flymake-display-err-menu-for-current-line)
(global-set-key (kbd "C-z f p") 'flymake-goto-prev-error)
(global-set-key (kbd "C-z f n") 'flymake-goto-next-error)
(global-set-key (kbd "C-z f b") 'flyspell-buffer)
(global-set-key (kbd "C-z f o") 'ff-find-other-file)
(global-set-key (kbd "C-z f r") 'ff-find-related-file)
(global-set-key (kbd "C-z f s") 'fd-switch-dictionary)
(global-set-key (kbd "C-z m a") 'mathematica-mode)
(global-set-key (kbd "C-z m g") 'gnus)
(global-set-key (kbd "C-z m s") 'matlab-shell)
(global-set-key (kbd "C-z m m") 'cdlatex-dollar)
(global-set-key (kbd "C-z m p") 'maplev-mode)
(global-set-key (kbd "C-z h c") 'hvj-count-words-region)
(global-set-key (kbd "C-z j m") 'jmaker-generate-makefile)
(global-set-key (kbd "C-z j a") 'jde-javadoc-autodoc-at-line)
(global-set-key (kbd "C-z j d") 'jde-javadoc-generate-javadoc-template)
(global-set-key (kbd "C-z j j") 'jde-complete)
(global-set-key (kbd "C-z j k") 'jde-compile)
(global-set-key (kbd "C-z j r") 'jde-run)
(global-set-key (kbd "C-z p p") 'rope-code-assist)
(global-set-key (kbd "C-z p a") 'reftex-parse-all)
(global-set-key (kbd "C-z p o") 'reftex-parse-one)
(global-set-key (kbd "C-z s d") 'rope-show-doc)

(global-set-key (kbd "C-z g d") 'gdb)
(global-set-key (kbd "C-z g m") 'gdb-many-windows)
(global-set-key (kbd "C-z k") 'browse-kill-ring)
(global-set-key (kbd "C-z l e") 'less-minor-mode)
(global-set-key (kbd "C-z l d") 'load-file)
(global-set-key (kbd "C-z g c") 'go-to-char)
(global-set-key (kbd "C-z g b") 'color-theme-blue-gnus)
(global-set-key (kbd "C-z g r") 'grep)
(global-set-key (kbd "C-z g f") 'grep-find)
(global-set-key (kbd "C-z g p") 'gnuplot-mode)
(global-set-key (kbd "C-z g g") 'magit-status)
(global-set-key (kbd "C-z n n") 'display-time-world)
(global-set-key (kbd "C-z n w") 'widen)
(global-set-key (kbd "C-z t o") 'occur)
(global-set-key (kbd "C-z o p") 'org-publish)
(global-set-key (kbd "C-z o s") 'org-set-tags)
(global-set-key (kbd "C-z o t") 'org-table-create)
(global-set-key (kbd "C-z o a") 'org-agenda-to-appt)
(global-set-key (kbd "C-z o o") 'org-export-icalendar-combine-agenda-files)
(global-set-key (kbd "C-z p g") 'gomoku)
(global-set-key (kbd "C-z p t") 'tetris)
(global-set-key (kbd "C-z p s") 'py-shell)
(global-set-key (kbd "C-z q") 'kill-this-buffer)
(global-set-key (kbd "C-z r r") 'query-replace-regexp)
(global-set-key (kbd "C-z r s") 'isearch-forward-regexp)
(global-set-key (kbd "C-z r b") 'isearch-backward-regexp)
(global-set-key (kbd "C-z r f") 'recentf-mode)
(global-set-key (kbd "C-z r o") 'run-octave)

(global-set-key (kbd "C-z s s") '(lambda() (interactive) (switch-to-buffer "*scratch*")))
(global-set-key (kbd "C-z s a") 'show-all)
(global-set-key (kbd "C-z s b") 'show-branches)
(global-set-key (kbd "C-z s e") 'show-entry)
(global-set-key (kbd "C-z s i") 'show-children)
(global-set-key (kbd "C-z s t") 'show-subtree)
(global-set-key (kbd "C-z h t") 'hide-subtree)
(global-set-key (kbd "C-z h s") 'hide-sublevels)
(global-set-key (kbd "C-z h l") 'hide-leaves)
(global-set-key (kbd "C-z h b") 'hide-body)
(global-set-key (kbd "C-z h e") 'hide-entry)
(global-set-key (kbd "C-z s m") 'slime)
;;(global-set-key (kbd "C-z t") 'thumbs)
(global-set-key (kbd "C-z v i") 'vi-mode)
;;(global-set-key (kbd "C-z v v") 'semantic-decoration-include-visit)

(global-set-key (kbd "C-z u d") 'dired-jump)
(global-set-key (kbd "C-z u f") 'folding-mode)
(global-set-key (kbd "C-z u o") 'outline-mode)
(global-set-key (kbd "C-z w w") 'w3m)
(global-set-key (kbd "C-z w p") 'browse-url-at-point)
(global-set-key (kbd "C-z x") 'emacs-lisp-byte-compile-and-load)
(global-set-key (kbd "C-z y") 'clipboard-yank)
(global-set-key (kbd "C-z z") 'set-mark-command)
(global-set-key (kbd "C-z C-z") 'set-mark-command)
(global-set-key (kbd "C-z a 1") 'c-mode-config-header)
(global-set-key (kbd "C-z a 2") 'make-header)
(global-set-key (kbd "C-z a 3") 'linum-mode)
(global-set-key (kbd "C-z a 4") 'hl-line-mode)
(global-set-key (kbd "C-z a 5") 'display-battery-mode)
(global-set-key (kbd "C-z a l") 'msf-abbrev-goto-root)
(global-set-key (kbd "C-z a a") 'msf-abbrev-define-new-abbrev-this-mode)
(global-set-key (kbd "C-z a s") 'ascii-table-show)
(global-set-key (kbd "C-z a m") 'abbrev-mode)
(global-set-key (kbd "C-z a t") 'hvj-line-to-top-of-window)
(global-set-key (kbd "C-z a t") 'hvj-line-to-top-of-window)
(global-set-key (kbd "C-z i i") 'yas/insert-snippet)
(global-set-key (kbd "C-z i d") 'indent-region)
(global-set-key (kbd "C-z i m") 'imaxima)
(global-set-key (kbd "C-z i w") 'woman)
(global-set-key (kbd "C-z i t") 'imath-mode)
(global-set-key (kbd "C-z t y") 'ecb-activate)
(global-set-key (kbd "C-z t d") 'ecb-deactivate)
(global-set-key (kbd "C-z t w") 'twit)
(global-set-key (kbd "C-x C-b") 'ibuffer)
(global-set-key (kbd "C-c z") 'msf-abbrev-abbrev-complete)

(define-key dired-mode-map "/m" 'ywb-dired-filter-regexp)
(define-key dired-mode-map "/." 'ywb-dired-filter-extension)

(global-set-key [f10] 'sr-speedbar-toggle)
(define-key speedbar-file-key-map "u" 'speedbar-up-directory)
(define-key speedbar-file-key-map "." 'speedbar-up-directory)
(global-set-key [f9] 'toggle-line-spacing)
(global-set-key [down-mouse-2]        'mouse-flash-position-or-M-x)
(global-set-key [S-down-mouse-2]      'mouse-scan-lines-or-M-:)
(global-set-key [mode-line C-mouse-1] 'mouse-tear-off-window)
(global-set-key (kbd "C-z t l") 'org-store-link)
(global-set-key (kbd "C-z t a") 'org-agenda)
(global-set-key (kbd "C-z t t") 'org-iswitchb)
(global-set-key [deletechar] 'c-hungry-delete-backwards)
(global-set-key "\C-ck" 'mode-compile-kill)
(global-set-key "\C-cc" 'mode-compile)
